﻿Imports System.ComponentModel
Public Class OutputViewModel
    Implements INotifyPropertyChanged
    Implements IOutputViewModel

    Private _processor As IOutputDataProcessor
    Private _view As OutputView

    ''' <summary>
    ''' Initializes a new instance of the OutputViewModel class.
    ''' </summary>
    ''' <param name="processor"></param>
    Public Sub New(ByVal view As OutputView, ByVal processor As IOutputDataProcessor)
        _processor = processor
        AddHandler _processor.PropertyChanged, AddressOf Me.PwmUpdated
        _view = view
        _view.DataContext = Me
    End Sub

    Private _header As String = "Robot Output"
    Public Property Header() As String Implements IOutputViewModel.Header
        Get
            Return _header
        End Get
        Set(ByVal Value As String)
            _header = Value
        End Set
    End Property

    Public Property Pwms() As Pwm() Implements IOutputViewModel.Pwms
        Get
            Return _processor.Pwms
        End Get
        Set(ByVal value As Pwm())
            _processor.Pwms = value
        End Set
    End Property

    Public Property View() As OutputView Implements IOutputViewModel.View
        Get
            Return _view
        End Get
        Set(ByVal value As OutputView)
            _view = value
        End Set
    End Property

    Private Sub PwmUpdated(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
        If e.PropertyName = "Pwms" Then
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Pwms"))
        End If
    End Sub

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

End Class
